<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文件上传测试</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      max-width: 800px;
      margin: 0 auto;
      padding: 20px;
    }
    .upload-form {
      margin-bottom: 20px;
      padding: 20px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }
    .upload-form h2 {
      margin-top: 0;
    }
    .upload-form input[type="file"] {
      margin-bottom: 10px;
    }
    .upload-form button {
      padding: 10px 15px;
      background-color: #4CAF50;
      color: white;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    }
    .upload-form button:hover {
      background-color: #45a049;
    }
    #response {
      margin-top: 20px;
      padding: 10px;
      border: 1px solid #ddd;
      border-radius: 5px;
      background-color: #f9f9f9;
    }
  </style>
</head>
<body>
  <h1>文件上传测试</h1>
  
  <div class="upload-form">
    <h2>单文件上传</h2>
    <form id="singleUploadForm">
      <input type="file" name="file" required>
      <button type="submit">上传</button>
    </form>
  </div>

  <div class="upload-form">
    <h2>多文件上传</h2>
    <form id="multipleUploadForm">
      <input type="file" name="files" multiple required>
      <button type="submit">上传</button>
    </form>
  </div>

  <div id="response"></div>

  <script>
    const responseDiv = document.getElementById('response');

    document.getElementById('singleUploadForm').addEventListener('submit', async (e) => {
      e.preventDefault();
      const formData = new FormData(e.target);
      try {
        const response = await fetch('/upload/single', {
          method: 'POST',
          body: formData
        });
        const result = await response.json();
        responseDiv.textContent = JSON.stringify(result, null, 2);
      } catch (error) {
        responseDiv.textContent = `上传失败: ${error.message}`;
      }
    });

    document.getElementById('multipleUploadForm').addEventListener('submit', async (e) => {
      e.preventDefault();
      const formData = new FormData(e.target);
      try {
        const response = await fetch('/upload/multiple', {
          method: 'POST',
          body: formData
        });
        const result = await response.json();
        responseDiv.textContent = JSON.stringify(result, null, 2);
      } catch (error) {
        responseDiv.textContent = `上传失败: ${error.message}`;
      }
    });
  </script>
</body>
</html> 